<?php

class CronController extends Controller
{
	/**
	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
	 * using two-column layout. See 'protected/views/layouts/column2.php'.
	 */
	// public $layout='//layouts/column2';

	/**
	 * Specifies the access control rules.
	 * This method is used by the 'accessControl' filter.
	 * @return array access control rules
	 */
	public function accessRules()
	{
		return array(
			array('allow',  // allow all users to perform 'index' and 'view' actions
				'actions'=>array('index','view'),
				'users'=>array('*'),
			),
			array('allow', // allow authenticated user to perform 'create' and 'update' actions
				'actions'=>array('create','update'),
				'users'=>array('@'),
			),
			array('allow', // allow admin user to perform 'admin' and 'delete' actions
				'actions'=>array('admin','delete'),
				'users'=>array('admin'),
			),
			array('deny',  // deny all users
				'users'=>array('*'),
			),
		);
	}
	public function action12h()
	{
			
	}
	public function action5min()
	{
		$jobs = Job::model()->findAll("status != 4 or status != 3");
		$bidjobs = Bidjob::model()->findAll("status = 2");
		foreach ($bidjobs as $key) {
			if(Yii::app()->getModule('job')->timeend(date("Y-m-d H:i:s"),$key->timeend) > 0 && $key->status != -1){
			}
		}
		foreach ($jobs as $key) {
			if(Yii::app()->getModule('job')->timeend(date("Y-m-d H:i:s"),$key->timeend) <= 0 && $key->status != -1){
				$key->status = -1;
				$key->save(false);
	            $str="$key->name đã hết hạn thời gian đăng ký làm. Hãy nâng cấp dự án của bạn.";
				Yii::app()->getModule('job')->createInboxmessage($key->id,0,'Bạn nhận được một tin nhắn',$str);	
				$link =  Yii::app()->request->hostInfo.Yii::app()->createUrl('/job/create/upgrade',array('id'=>$key->id,));
				$title = $data->user->name." đã hết hạn làm";
		    	$content ="Dear ".$key->user->name." </br> Dự án ".$key->name." đã hết hạn, hãy nâng cấp thời gian tiếp theo cho nó. </br>
		    	<a href='$link'>Nâng cấp dự án</a>";
		    	Yii::app()->getModule('job')->sendMail($title,$content,$key->user->email);
				echo $key->id;
			}
		}
		// echo var_dump($jobs);
	}

}
